#!/bin/bash

#! amount args
# ${_is_amount_arg} ${NARGS} min_equ max_equ
# if [ $? -ne 0 ]; then
#     plt_pause "from ${FNN}() :: ${_is_amount_arg} ${NARGS} min_equ:: be return 1"
#     return 1
# fi
#! normalize ptr_path -> absolut path
# ptr_path=$1
# ptr_path=$(${_abs_path} $PPWD "ptr_path") #ptr args
#! variables for cr_f_dir_insert_
# fn_name=$(${_prs_f} -n ${arg_path})
# root_path=$(${_prs_f} -d ${arg_path})
#! search in array
# [[ " ${arr[*]} " =~ " $1 " ]] && echo "true" || echo "false"
#! ${array[@]:1} all from 1 member arr

# echo -e "${GREEN}\${g_args[@]} = ${g_args[*]}${NORMAL}" #print variable
# echo -e "${GREEN}\${e_args[@]} = ${e_args[*]}${NORMAL}" #print variable
# echo -e "${GREEN}\${f_args[@]} = ${f_args[*]}${NORMAL}" #print variable
# echo -e "${GREEN}\${ARGS[@]} = ${ARGS[*]}${NORMAL}"     #print variable
# echo -e "${GREEN}\${NARGS} = ${NARGS}${NORMAL}"         #print variable
# echo -e "${GREEN}\${ARGS0} = ${ARGS0}${NORMAL}"         #print variable
# echo -e "${GREEN}\${ARGS1} = ${ARGS1}${NORMAL}"         #print variable
# echo -e "${GREEN}\${ARGS2} = ${ARGS2}${NORMAL}"         #print variable

# echo -e "${GREEN}\${dir_fns_} = ${dir_fns_}${NORMAL}" #print variable

# echo -e "${GREEN}\${local_var_wrap_arr[@]} = ${local_var_wrap_arr[*]}${NORMAL}" #print variable
# echo -e "${GREEN}\${local_var_fn_arr[@]} = ${local_var_fn_arr[*]}${NORMAL}"     #print variable

# echo -e "${GREEN}\$ratis = $ratis${NORMAL}" #print variable

# echo "that ${FNN}.sal"

#! every from list_strong_cntls by able
# list_strong_cntls=(?str_ ?del_ ?parr_)
# for item in "${list_strong_cntls[@]}"; do
#     echo -e "${GREEN}\$item = $item${NORMAL}" #print variable
#     echo "$(eval echo \$"$item")"
#     if [ -z "$(eval echo \$"$item")" ]; then
#         plt_info "from ${FNN}() :: $item is empty :: be return 1"
#         return 1
#     fi
# done

#! once dpl_ or bcp_ mast be able (0 1)
# sum_1=$((${dpl_:-0} + ${bcp_:-0}))
# echo -e "${GREEN}\$sum_1 = $sum_1${NORMAL}"

# if [ "${sum_1:-0}" -ne 1 ]; then
#     plt_info "from ${FNN}() once dpl_ or bcp_ mast be able :: be return 1"
#     return 1
# fi

#?--------------------------------------------------------
#?---------------------------------------------
#?---------------------------------------

# PS3_OLD=PS3                   # This preserves whatever the value of the bash builtin environment variable PS3 was.
# PS3="be exec file dilectus: " # ← enter a prompt that asks the user to select from a list of items. If you're feeling helpful, explain what will happen with the item that the user selects.

dir_ff="${PLT_PATH}/.d/.exec.f/free_function"

echo "free file exec dir: file://$dir_ff"

if ! [ -d "${dir_ff}" ]; then
    plt_exit "in mm_execf_ : NOT_DIR '${dir_ff}' return 1"
    return 1
fi

echo -e "${BLUE}--- exec ${FNN} (num_menu) ---${NORMAL}" #started functions

itr="d2e ${dir_ff}"

value_itr=0

for item in $(${itr}); do
    ((value_itr++))
done

if [ "$(num_01 "$1")" -eq 1 ] && [ "$1" -le "${value_itr}" ]; then

    num_res=$(($1 - 1))

    ii=0

    for item in $(d2e ${dir_ff}); do

        if [ ${ii} -eq ${num_res} ]; then
            choice=${item}
            echo -e "${GREEN}\$choice = $choice${NORMAL}" #print variable
            break
        fi

        ((ii++))

    done

    u_item=${dir_ff}/${choice}

    echo -e "${GREEN}\$u_item = $u_item${NORMAL}" #print variable

    if [ -f "${u_item}" ]; then
        echo -e "${HLIGHT}--- . ${u_item} ---${NORMAL}" #start files
        . "${u_item}"
        
    else
        plt_exit "in mm_execf_ : NOT_FILE : '${u_item}' return 1"
        return 1
    fi

    return 0

fi

PS3="be exec file dilectus:"

select item in $(d2e ${dir_ff}); do

    # echo -e "${GREEN}\$item = $item${NORMAL}" #print variable

    u_item=${dir_ff}/${item}

    if [ -f "${u_item}" ]; then

        echo -e "${HLIGHT}--- . ${u_item} ---${NORMAL}" #start files
        . "${u_item}"
        ${FNN}
    else
        plt_exit "in mm_execf_ : NOT_FILE : '${u_item}' return 1"
        return 1
    fi

done
#{zzz20}

# select delectus in $(d2e "${dir_ff}"); do

#     file_this="${dir_ff}/${delectus}"

#     if ! [ -f "${file_this}" ]; then
#         plt_exit "in mm_execf_ : NOT_FILE '${file_this}' return 1"
#         return 1
#     fi

#     echo -e "${HLIGHT}--- . ${file_this} ---${NORMAL}" #start files
#     . "${file_this}"

#     break
# done

#?---------------------------------------
#?---------------------------------------------
#?--------------------------------------------------------
